﻿using System;
using System.Xml;
using System.Web;

namespace CaiBaby.Common
{
    /// <summary>
    /// web.config 配置类
    /// </summary>
    public class ConfigHelper
    {
        /// <summary>
        /// 数据库Db3721up的连接字符串
        /// </summary>
        public static string CaiBabyDBConnStr
        {
            get
            {
                try
                {
                    return GetConnStrByName("CaiBabyDBConnStr");
                }
                catch
                {
                    return string.Empty;
                }

            }
        }
 
        /// <summary>
        /// 读取值web.config里面的用户配置值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetValue(string key)
        {
            return System.Configuration.ConfigurationManager.AppSettings[key];
        }

        /// <summary>
        /// 获取web.config数据库连接字符串
        /// </summary>
        /// <param name="name">字符串名</param>
        /// <returns></returns>
        public static string GetConnStrByName(string name)
        {
            return System.Configuration.ConfigurationManager.ConnectionStrings[name].ToString();
        }

        /// <summary>
        /// 获取web.config 中最大可上传文件大小限制(单位：m)
        /// </summary>
        /// <returns></returns>
        public static int MaxUploadLength
        {
            get
            {
                int max = Int32.Parse(GetValue("set_maxUploadSize"));
                return max;
            }
        }
    }
}